package com.xkdx.guangguang.fragment.my.setup;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;

import com.xkdx.guangguang.module.network.AbsModule;

public class PointModule extends AbsModule {
	Point point;

	@Override
	public void parseData() throws Exception {
		backJson = (JSONArray) result;
		try {
			for (int i = 0; i < backJson.length(); i++) {
				jsonObj = (JSONObject) backJson.get(i);
				String sortOfAct = jsonObj.getString("Act");
				if (sortOfAct.equals("ScoreLog")) {
//					point = parsePoint(jsonObj.getJSONObject("Content"));
                    point = parsePoint(jsonObj);
				}

			}
		} catch (Exception e) {
			throw e;
		}

	}

	private Point parsePoint(JSONObject person) throws Exception {
		Point point=new Point();
		try {
			if (person == null) {
				return null;
			}
//			JSONObject stut = (JSONObject) person.get("Result");
			point.setMessage(person.getString("Message"));
			point.setStatus(person.getString("Code"));

//			if (person.has("DetailInfo")) {
//				JSONObject detail = person.getJSONObject("DetailInfo");
////				point.setPoint(detail.getString("Point"));
////				point.setNickName(detail.getString("NickName"));
//			}
			if (person.has("DetailInfo")) {

				JSONArray array = person.getJSONArray("DetailInfo");

				List<Map<String, String>> list = new ArrayList<Map<String, String>>();
				for (int i = 0; i < array.length(); i++) {
					JSONObject item = (JSONObject) array.opt(i);
					Map<String, String> map = new HashMap<String, String>();
					map.put("ID", item.getString("id"));
					map.put("Type", item.getString("type"));
					map.put("Memo", item.getString("desc"));
					map.put("Point", item.getString("coin"));
					map.put("CreateTime", item.getString("ctime"));
					list.add(map);

				}
				point.setPointList(list);

			}

		} catch (Exception e) {
			throw e;
		}
		return point;

	}

	public class Point implements Serializable {
		String UserID;
		String NickName;
		String Point;
		String Type;
		List<Map<String, String>> pointList;
		String Message;
		String Status;

		public String getStatus() {
			return Status;
		}

		public void setStatus(String status) {
			Status = status;
		}

		public String getMessage() {
			return Message;
		}

		public void setMessage(String message) {
			Message = message;
		}

		public String getType() {
			return Type;
		}

		public void setType(String type) {
			Type = type;
		}

		public String getUserID() {
			return UserID;
		}

		public void setUserID(String userID) {
			UserID = userID;
		}

		public String getNickName() {
			return NickName;
		}

		public void setNickName(String nickName) {
			NickName = nickName;
		}

		public String getPoint() {
			return Point;
		}

		public void setPoint(String point) {
			Point = point;
		}

		public List<Map<String, String>> getPointList() {
			return pointList;
		}

		public void setPointList(List<Map<String, String>> pointList) {
			this.pointList = pointList;
		}

	}

}
